package demo.practice.leetcode_base;

public class P278 {
    boolean isBadVersion(int version){
        if(version>=1)
            return true;
        else
            return false;
    }

    public static void main(String[] args) {

        P278 p278= new P278();
        p278.firstBadVersion(2);
    }
    public int firstBadVersion(int n) {
        if(isBadVersion(1))
            return 1;
        return firstBadVersion(n,1);
    }
    //min false max true
    public int firstBadVersion(int max,int min){
        while (max-min>1){
            System.out.println(String.format("max:%s min:%s max-min:%s",max,min,max-min));
            if(isBadVersion(max)&& !isBadVersion(min)){
                int middle= (max-min)/2 + min;
                if(!isBadVersion(middle))
                min=middle;
                else
                    max=middle;
            }else
                return -1;
        }
        return max;
    }




}
